package com.xiaoy.core.basic.security.entity;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.xiaoy.core.basic.organization.entity.Party;
import com.xiaoy.util.store.config.ConfigTable;

@Entity
@Table(name = ConfigTable.Basic.SECURITY_PARTYROLE)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) 
@SequenceGenerator(sequenceName = ConfigTable.Basic.SECURITY_PARTYROLE+"_SEQ", name = ConfigTable.Basic.SECURITY_PARTYROLE+"_SEQ", allocationSize = 1)
public class PartyRole {

	private long id;
	
	private String name;
	
	private long priority;
	
	private Party party;
	
	private Role role;
	
	public PartyRole (){}
	
	public PartyRole (long roleId,Party party){
		role = new Role(roleId);
		this.party = party;
	}
	
	public PartyRole (long roleId) {
		role = new Role(roleId);
	}
	

	
	
	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = ConfigTable.Basic.SECURITY_PARTYROLE+"_SEQ")
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public long getPriority() {
		return priority;
	}

	public void setPriority(long priority) {
		this.priority = priority;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pratyid")
	public Party getParty() {
		return party;
	}

	public void setParty(Party party) {
		this.party = party;
	}
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "roleid")
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}
	
	
}
